package sol.leetcode;

/**
 * Created by lkk on 2016/8/27.
 */
public class Issue258 {
    public static int addDigits(int num) {
        int sumDigits = 0;//用于记录每一位累加之和
        while (num != 0) {//num=0代表处理完一次累加结果
            sumDigits += num % 10;
            num /= 10;
            if (num == 0 && sumDigits > 9) {
                num = sumDigits;
                sumDigits = 0;
            }
        }
        return sumDigits;
    }

    public static void main(String[] args) {
        System.out.println(addDigits(1415));
    }
}
